﻿using System;
using System.Linq;
using System.Reflection;

namespace CommonUtils
{
    public static class AssemblyUtil
    {
        public static string GetNameOnly(this Assembly assembly)
        => assembly.GetName().Name;

        public static Assembly Get(string path)
        => Assembly.LoadFile(path);

        public static Type GetFirstOrDefaultClassType(this Assembly assembly)
        => assembly.GetExportedTypes().FirstOrDefault();

        public static string GetFirstOrDefaultClassName(this Assembly assembly)
        => assembly.GetFirstOrDefaultClassType().FullName;

        public static string GetFirstOrDefaultClassName(this string path)
        => Get(path).GetFirstOrDefaultClassName();
    }
}
